var wx_img;
var ali_img;
$(document).ready(function(){
    var params = {};
    mzpost({
        url:pub_orde_moneys,
        data:params,
        success:function(res){
            if(res.code == '2000'){
               var data = res.data;
                var pay_type = data.pay_type;
                 wx_img = pay_type.wx_img;
                 ali_img = pay_type.ali_img;

                var unpay = data.unpay;
                $('#money_owe').text(unpay.money_owe+'元');
                $('#money').text(unpay.money+'元');


                var id = unpay.id;
                var add_time = formateDate(unpay.add_time);

                $('#noticebtn').click(function(){
                    noticemsg(id)
                })


                var payed = data.payed;
                createList(payed)
            }else{
                mui.toast(res.msg);
            }
        },
        error:function(err){
            
            mui.toast('获取货款错误');
        }
    })


    $('.close').click(function(){
        $('.qrcodebox').addClass('mui-hidden');
    })
   
})

function createList(data){
    $.each(data,function(i,item){
        $('#title').after('<div class="mui-row">'+
        ' <div class="mui-col-xs-6 cell">'+formateDate(item.add_time)+'</div>'+
         ' <div class="mui-col-xs-6 cell">'+item.money+'</div>'+
    '</div>');
    })
}


function noticemsg(id){
    var pay_type = $('#wx').prop('checked') ? '1' : '2';
    var params = {id:id,pay_type:pay_type};
    mzpost({
        url:pub_notice,
        data:params,
        success:function(res){
            if(res.code == '2000'){
                mui.toast(res.msg);
            }else{
                mui.toast(res.msg);
            }
        },
        error:function(err){
            
            mui.toast('通知错误');
        }
    })
}


function download() {
   
    if( $('#wx').prop('checked')){
        downloadIamge('#qrcode','脉赚网官方微信收款码')
    }else{
        downloadIamge('#qrcode','脉赚网官方支付宝收款码')
    }
}

function showqrcode(){
    if($('#wx').prop('checked')){

        $('#qrcodename').text('脉赚网官方微信收款码');
        $('#qrcode').attr('src',wx_img);

    }else{

        $('#qrcodename').text('脉赚网官方支付宝收款码');
        $('#qrcode').attr('src',ali_img);

    }
    $('.qrcodebox').removeClass('mui-hidden');
}